/**
 * Created by HAIWEI-LC on 2019/10/23
 */
package com.hw.paltfrom.controller.system;

import com.hw.paltfrom.pack.ResponseResult;
import com.hw.paltfrom.pojo.HwBaseCountycore;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.service.system.CountycoreService;
import com.hw.paltfrom.utils.ResponeResultUtil;
import com.hw.paltfrom.utils.VerifyUtil;
import com.hw.paltfrom.vo.BaseCountycoreVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;


@RestController
@RequestMapping("/countycore")
public class CountycoreContoller {

    @Autowired
    private CountycoreService countycoreService;


    //过滤空Date数据
    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }


    //增加超限检测站
    @RequestMapping("/add")
    public Map<String, Object> add(BaseCountycoreVO vo){
        if (!VerifyUtil.verifyParams(vo)){
            return ResponseResult.fail(HWSystemCode.PARAMS_ERROR);
        }
        return countycoreService.add(vo);
    }

    //查询超限监测站
    @RequestMapping("/find")
    public Map<String, Object> findCountyCore(BaseCountycoreVO vo){
        if (vo.getPageNum() <= 0){
            vo.setPageNum(0);
        }
        if (vo.getPageSize() == 0){
            vo.setPageSize(5);
        }
        return countycoreService.findCountyCore(vo);
    }

    //删除超限检测站
//    @PostMapping("/delete")
//    public Map<String, Object> deleteByCountycoreId(@RequestBody Map<String,String> map){
//        if (StringUtils.isBlank(map.get("fCountycoreids")) || StringUtils.isBlank(map.get("fModifyuserid")) || StringUtils.isBlank(map.get("fModifyusername"))){
//            return ResponeResultUtil.fail(HWSystemCode.PARAMS_ERROR);
//        }
//        return (Map<String, Object>) countycoreService.deleteById(map.get("fCountycoreids"),map.get("fModifyuserid"),map.get("fModifyusername"));
//    }
    @PostMapping("/delete")
    public Map<String, Object> deleteByCountycoreId(String fCountycoreids,String fModifyuserid,String fModifyusername){
        //校验必填参数
        if (StringUtils.isBlank(fCountycoreids) || StringUtils.isBlank(fModifyuserid) || StringUtils.isBlank(fModifyusername)){
            return ResponeResultUtil.fail(HWSystemCode.PARAMS_ERROR);
        }
        return countycoreService.deleteById(fCountycoreids,fModifyuserid,fModifyusername);
    }

    //修改超限检测站
    @PostMapping("/update")
    public Map<String, Object> updateCountrycore(HwBaseCountycore hwBaseCountycore){
        //校验必填参数
        if (StringUtils.isBlank(hwBaseCountycore.getfCountycoreid()) || StringUtils.isBlank(hwBaseCountycore.getfModifyuserid()) ||
                StringUtils.isBlank(hwBaseCountycore.getfModifyusername())){
            return ResponeResultUtil.fail(HWSystemCode.PARAMS_ERROR);
        }
        return countycoreService.updateCountrycore(hwBaseCountycore);
    }
}
